<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <div th:insert="/common.html"></div>
</head>
<body>
<h1>登录页面</h1>
<span th:text="${msg}" style="color:red"></span>
<form method="post" >
    用户名:<input type="text" id="pname" name="pname"/><br/>
    密码：<input type="password" id="pwd" name="pwd"/><br/>
    <input type="button" value="登录" onclick="login()"/>
</form>
<script>
    function login(){
        $.ajax({
            url:"/loginController/login",
            data:{pname:$("#pname").val(),pwd:$("#pwd").val()},//表单序列化
            dataType:"json",
            type:"post",
            async:false,
            success:function(data){
                if(data.code==0){
                    alert(data.msg);
                    location.href="/"
                }else{
                    alert(data.msg);
                }
            },
            error:function(){
                alert("系统错误，请联系管理员");
            }
        })
    }
</script>
</body>
</html>